home *** CD-ROM | disk | FTP | other *** search
/ Aminet 49 / Aminet 49 (2002)(GTI - Schatztruhe)[!][Jun 2002].iso / Aminet / util / libs / ttrender.lha / ttrender-2.0 / Developer / source / sfnt / sfdriver.c next >
Encoding:
C/C++ Source or Header  |  2002-04-06  |  7.0 KB  |  305 lines

  1. /***************************************************************************/
  2. /*                                                                         */
  3. /*  sfdriver.c                                                             */
  4. /*                                                                         */
  5. /*    High-level SFNT driver interface (body).                             */
  6. /*                                                                         */
  7. /*  Copyright 1996-2001 by                                                 */
  8. /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
  9. /*                                                                         */
  10. /*  This file is part of the FreeType project, and may only be used,       */
  11. /*  modified, and distributed under the terms of the FreeType project      */
  12. /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
  13. /*  this file you indicate that you have read the license and              */
  14. /*  understand and accept it fully.                                        */
  15. /*                                                                         */
  16. /***************************************************************************/
  17.  
  18.  
  19. #include <ft2build.h>
  20. #include FT_INTERNAL_SFNT_H
  21. #include FT_INTERNAL_OBJECTS_H
  22.  
  23. #include "sfdriver.h"
  24. #include "ttload.h"
  25. #include "ttcmap.h"
  26. #include "sfobjs.h"
  27.  
  28. #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
  29. #include "ttsbit.h"
  30. #endif
  31.  
  32. #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
  33. #include "ttpost.h"
  34. #endif
  35.  
  36. #include <string.h>     /* for strcmp() */
  37.  
  38.  
  39.   static void*
  40.   get_sfnt_table( TT_Face      face,
  41.                   FT_Sfnt_Tag  tag )
  42.   {
  43.     void*  table;
  44.  
  45.  
  46.     switch ( tag )
  47.     {
  48.     case ft_sfnt_head:
  49.       table = &face->header;
  50.       break;
  51.  
  52.     case ft_sfnt_hhea:
  53.       table = &face->horizontal;
  54.       break;
  55.  
  56.     case ft_sfnt_vhea:
  57.       table = face->vertical_info ? &face->vertical : 0;
  58.       break;
  59.  
  60.     case ft_sfnt_os2:
  61.       table = face->os2.version == 0xFFFF ? 0 : &face->os2;
  62.       break;
  63.  
  64.     case ft_sfnt_post:
  65.       table = &face->postscript;
  66.       break;
  67.  
  68.     case ft_sfnt_maxp:
  69.       table = &face->max_profile;
  70.       break;
  71.  
  72.     case ft_sfnt_pclt:
  73.       table = face->pclt.Version ? &face->pclt : 0;
  74.       break;
  75.  
  76.     default:
  77.       table = 0;
  78.     }
  79.  
  80.     return table;
  81.   }
  82.  
  83.  
  84. #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
  85.  
  86.  
  87.   static FT_Error
  88.   get_sfnt_glyph_name( TT_Face     face,
  89.                        FT_UInt     glyph_index,
  90.                        FT_Pointer  buffer,
  91.                        FT_UInt     buffer_max )
  92.   {
  93.     FT_String*  gname;
  94.     FT_Error    error;
  95.  
  96.  
  97.     error = TT_Get_PS_Name( face, glyph_index, &gname );
  98.     if ( !error && buffer_max > 0 )
  99.     {
  100.       FT_UInt  len = (FT_UInt)( strlen( gname ) );
  101.  
  102.  
  103.       if ( len >= buffer_max )
  104.         len = buffer_max - 1;
  105.  
  106.       MEM_Copy( buffer, gname, len );
  107.       ((FT_Byte*)buffer)[len] = 0;
  108.     }
  109.  
  110.     return error;
  111.   }
  112.  
  113.  
  114.   static const char*
  115.   get_sfnt_postscript_name( TT_Face  face )
  116.   {
  117.     FT_Int  n, found_win, found_apple;
  118.  
  119.  
  120.     /* shouldn't happen, but just in case to avoid memory leaks */
  121.     if ( face->root.internal->postscript_name )
  122.       return face->root.internal->postscript_name;
  123.  
  124.     /* scan the name table to see whether we have a Postscript name here, */
  125.     /* either in Macintosh or Windows platform encodings                  */
  126.     found_win     = -1;
  127.     found_apple   = -1;
  128.     
  129.     for ( n = 0; n < face->num_names; n++ )
  130.     {
  131.       TT_NameRec*  name = face->name_table.names + n;
  132.  
  133.  
  134.       if ( name->nameID == 6 && name->string != NULL )
  135.       {
  136.         if ( name->platformID == 3     &&
  137.              name->encodingID == 1     &&
  138.              name->languageID == 0x409 )
  139.           found_win = n;
  140.           
  141.         if ( name->platformID == 1 &&
  142.              name->encodingID == 0 &&
  143.              name->languageID == 0 )
  144.           found_apple = n;
  145.       }
  146.     }
  147.     
  148.     if ( found_win )
  149.     {
  150.       FT_Memory    memory = face->root.memory;
  151.       TT_NameRec*  name   = face->name_table.names + found_win;
  152.       FT_UInt      len    = name->stringLength/2;
  153.       FT_Error     error;
  154.       FT_String*   result;
  155.       
  156.       if ( !ALLOC( result, len+1 ) )
  157.       {
  158.         FT_String*  r = result;
  159.         FT_Byte*    p = (FT_Byte*) name->string;
  160.         
  161.         for ( ; len > 0; len--, p += 2 )
  162.         {
  163.           if ( p[0] == 0 && p[1] >= 32 && p[1] < 128 )
  164.             *r++ = p[1];
  165.         }
  166.         *r = '\0';
  167.       }
  168.       return result;
  169.     }
  170.  
  171.     if ( found_apple )
  172.     {
  173.       FT_Memory    memory = face->root.memory;
  174.       TT_NameRec*  name   = face->name_table.names + found_win;
  175.       FT_UInt      len    = name->stringLength;
  176.       FT_Error     error;
  177.       FT_String*   result;
  178.       
  179.       if ( !ALLOC( result, len+1 ) )
  180.       {
  181.         MEM_Copy( result, name->string, len );
  182.         result[len] = '\0';
  183.       }
  184.       return result;
  185.     }
  186.  
  187.     return NULL;
  188.   }
  189.  
  190.  
  191. #endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
  192.  
  193.  
  194.   FT_CALLBACK_DEF( FT_Module_Interface )
  195.   SFNT_Get_Interface( FT_Module    module,
  196.                       const char*  interface )
  197.   {
  198.     FT_UNUSED( module );
  199.  
  200.     if ( strcmp( interface, "get_sfnt" ) == 0 )
  201.       return (FT_Module_Interface)get_sfnt_table;
  202.  
  203. #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
  204.     if ( strcmp( interface, "glyph_name" ) == 0 )
  205.       return (FT_Module_Interface)get_sfnt_glyph_name;
  206. #endif
  207.  
  208.     if ( strcmp( interface, "postscript_name" ) == 0 )
  209.       return (FT_Module_Interface)get_sfnt_postscript_name;
  210.  
  211.     return 0;
  212.   }
  213.  
  214.  
  215.   static
  216.   const SFNT_Interface  sfnt_interface =
  217.   {
  218.     TT_Goto_Table,
  219.  
  220.     SFNT_Init_Face,
  221.     SFNT_Load_Face,
  222.     SFNT_Done_Face,
  223.     SFNT_Get_Interface,
  224.  
  225.     TT_Load_Any,
  226.     TT_Load_SFNT_Header,
  227.     TT_Load_Directory,
  228.  
  229.     TT_Load_Header,
  230.     TT_Load_Metrics_Header,
  231.     TT_Load_CMap,
  232.     TT_Load_MaxProfile,
  233.     TT_Load_OS2,
  234.     TT_Load_PostScript,
  235.  
  236.     TT_Load_Names,
  237.     TT_Free_Names,
  238.  
  239.     TT_Load_Hdmx,
  240.     TT_Free_Hdmx,
  241.  
  242.     TT_Load_Kern,
  243.     TT_Load_Gasp,
  244.     TT_Load_PCLT,
  245.  
  246. #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
  247.  
  248.     /* see `ttload.h' */
  249.     TT_Load_Bitmap_Header,
  250.  
  251.     /* see `ttsbit.h' */
  252.     TT_Set_SBit_Strike,
  253.     TT_Load_SBit_Strikes,
  254.     TT_Load_SBit_Image,
  255.     TT_Free_SBit_Strikes,
  256.  
  257. #else /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
  258.  
  259.     0,
  260.     0,
  261.     0,
  262.     0,
  263.     0,
  264.  
  265. #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
  266.  
  267. #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
  268.  
  269.     /* see `ttpost.h' */
  270.     TT_Get_PS_Name,
  271.     TT_Free_Post_Names,
  272.  
  273. #else /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
  274.  
  275.     0,
  276.     0,
  277.  
  278. #endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
  279.  
  280.     /* see `ttcmap.h' */
  281.     TT_CharMap_Load,
  282.     TT_CharMap_Free,
  283.   };
  284.  
  285.  
  286.   FT_CALLBACK_TABLE_DEF
  287.   const FT_Module_Class  sfnt_module_class =
  288.   {
  289.     0,  /* not a font driver or renderer */
  290.     sizeof( FT_ModuleRec ),
  291.  
  292.     "sfnt",     /* driver name                            */
  293.     0x10000L,   /* driver version 1.0                     */
  294.     0x20000L,   /* driver requires FreeType 2.0 or higher */
  295.  
  296.     (const void*)&sfnt_interface,  /* module specific interface */
  297.  
  298.     (FT_Module_Constructor)0,
  299.     (FT_Module_Destructor) 0,
  300.     (FT_Module_Requester)  SFNT_Get_Interface
  301.   };
  302.  
  303.  
  304. /* END */
  305.